package threading;

public class ThreadDemo6Join2 {
    public static void main(String[] args) throws InterruptedException {
        //想要同时启动20个线程，应该想到数组
        Thread[] threads = new Thread[20];
        //创建线程
        for (int i = 0; i < 20; i++) {
            int num = i;
            //这是创建新线程了，应该是补充数组里的线程
            /*Thread thread = new Thread(() -> {
                System.out.println(num);
            });*/
            threads[i] = new Thread(()-> {
                System.out.println(num);
            });
        }

        //依次启动
        for (Thread t:threads) {
            t.start();
        }
        //主线程等待新线程完成
        for (Thread t:threads) {
            t.join();
        }

        System.out.println("OK");
    }
}
